<?php

/* this is to handle database upgrades from Version 1.1.96rc2 on: */

global $database;

//joomla 1.5 compat::
if( is_null( $database ) && class_exists('jfactory')) {
		$database = JFactory::getDBO();
	}
//1196 - 1197 upgrades
$database->setQuery("show columns from #__osc_products");
$result = $database->loadObjectList();
$tcheck = array();
foreach($result as $check) {
$tcheck[]=$check->Field;
}

if (!in_array("affiliate_allow_product" , $tcheck)){
echo '<h3>Doing the 1.1.96 to 1.1.97 Database Upgrades</h3>';


$database->setQuery("ALTER TABLE `#__osc_products` ADD `affiliate_allow_product` TINYINT(1)  DEFAULT '1' NOT NULL");
$database->query();
echo '<li>Added affilate allow product key to products table</li>';

$database->setQuery("CREATE TABLE IF NOT EXISTS #__osc_customers_to_extra_fields (
  customers_id int(11) NOT NULL default '0',
  fields_id int(11) NOT NULL default '0',
  `value` text
)");
$result=$database->query();
echo '<li>Added customers extra fields table</li>';

$database->setQuery("CREATE TABLE IF NOT EXISTS #__osc_extra_fields (
  fields_id int(11) NOT NULL auto_increment,
  fields_input_type int(11) NOT NULL default '0',
  fields_input_value text NOT NULL,
  fields_status tinyint(2) NOT NULL default '0',
  fields_required_status tinyint(2) NOT NULL default '0',
  fields_size int(5) NOT NULL default '0',
  fields_required_email tinyint(2) NOT NULL default '0',
  PRIMARY KEY  (fields_id)
)");
$result=$database->query();
echo '<li>Added customers extra fields table</li>';

$database->setQuery("CREATE TABLE IF NOT EXISTS #__osc_extra_fields_info (
  fields_id int(11) NOT NULL default '0',
  languages_id int(11) NOT NULL default '0',
  fields_name varchar(32) NOT NULL default ''
)");
$result=$database->query();
echo '<li>Added customers extra fields table</li>';

$database->setQuery("Update #__osc_configuration set configuration_group_id = 10 where configuration_group_id = 11");
$database->query();
echo '<li>Cleared up configuration table</li>';

$database->setQuery("Delete from #__osc_configuration_group where configuration_group_id = 11");
$database->query();

$database->setQuery("Update #__osc_configuration_group set configuration_group_title = 'Logging / Cache', configuration_group_description = 'Logging / Cache configuration options' where configuration_group_id = 10");
$database->query();


$query = "ALTER TABLE `#__osc_customers` CHANGE `customers_password` `customers_password` VARCHAR( 100 )";
$database->setQuery($query);
echo '<li>Increased customers password field</li>';
$result = $database->query();
$query = "Delete from #__components where link='option=com_oscommerce&osMod=supplier_area'";
$database->setQuery($query);
$result=$database->query();


$query = "UPDATE `#__osc_configuration` SET `configuration_group_id` = '1' WHERE configuration_key = '_AUTO_LOGIN'";
$database->setQuery($query);
$result = $database->query();
echo '<li>Updated location of automatic login switch</li>';

$database->setQuery("UPDATE `#__osc_configuration` SET `configuration_title` = 'Use Quote system', `configuration_description` = 'Use Quote System, if false will not display the quote button but rather the add to cart button' WHERE `configuration_key` ='GALLARY_QUOTE'") ;
$result=$database->query();

$database->setQuery("INSERT IGNORE INTO `#__osc_configuration` (`configuration_id`, `configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('', 'Show Subscriptions', 'SHOW_SUBS', 'true', 'Show Subscriptions section under my account to users', 1, 20, '0000-00-00 00:00:00', '2005-03-19 02:32:40', '', 'tep_cfg_select_option(array(''true'', ''false''),')");
$result=$database->query();
echo '<li>Added show subscriptions switch</li>';




}


//1197 - 1198
$database->setQuery("show columns from #__osc_products");
$result = $database->loadObjectList();
$tcheck = array();
foreach($result as $check) {
$tcheck[]=$check->Field;
}
if (!in_array("products_price1" , $tcheck)){
echo '<h3>Doing the 1.1.97 to 1.1.98 Database Upgrades</h3>';


$database->setQuery("CREATE TABLE if not exists #__osc_products_extra_fields (
  products_extra_fields_id int NOT NULL auto_increment,
  products_extra_fields_name varchar(64) NOT NULL default '',
  products_extra_fields_order int(3) NOT NULL default '0',
  products_extra_fields_status tinyint(1) NOT NULL default '1',
  languages_id int(11) NOT NULL default '0',
  PRIMARY KEY (products_extra_fields_id)
)");
$database->query();
echo '<li>Created extra fields table for products<li>';

$database->setQuery("CREATE TABLE if not exists #__osc_products_to_products_extra_fields (
  products_id int NOT NULL,
  products_extra_fields_id int NOT NULL,
  products_extra_fields_value varchar(64),
  PRIMARY KEY (products_id,products_extra_fields_id)
)");
$database->query();
echo '<li>Created products to products extra fields linkage table<li>';

$database->setQuery("alter table #__osc_products 
add column products_price1 decimal(15,4) not null default 0.0,
add column products_price2 decimal(15,4) not null default 0.0,
add column products_price3 decimal(15,4) not null default 0.0,
add column products_price4 decimal(15,4) not null default 0.0,
add column products_price5 decimal(15,4) not null default 0.0,
add column products_price6 decimal(15,4) not null default 0.0,
add column products_price7 decimal(15,4) not null default 0.0,
add column products_price8 decimal(15,4) not null default 0.0,
add column products_price1_qty int not null default 0,
add column products_price2_qty int not null default 0,
add column products_price3_qty int not null default 0,
add column products_price4_qty int not null default 0,
add column products_price5_qty int not null default 0,
add column products_price6_qty int not null default 0,
add column products_price7_qty int not null default 0,
add column products_price8_qty int not null default 0,
add column products_qty_blocks int not null default 1");
$database->query();
echo '<li>altered products table added pricebreak fields</li>';

$database->setQuery("alter table #__osc_products_groups
add column products_price1 decimal(15,4) not null default 0.0,
add column products_price2 decimal(15,4) not null default 0.0,
add column products_price3 decimal(15,4) not null default 0.0,
add column products_price4 decimal(15,4) not null default 0.0,
add column products_price5 decimal(15,4) not null default 0.0,
add column products_price6 decimal(15,4) not null default 0.0,
add column products_price7 decimal(15,4) not null default 0.0,
add column products_price8 decimal(15,4) not null default 0.0,
add column products_price1_qty int not null default 0,
add column products_price2_qty int not null default 0,
add column products_price3_qty int not null default 0,
add column products_price4_qty int not null default 0,
add column products_price5_qty int not null default 0,
add column products_price6_qty int not null default 0,
add column products_price7_qty int not null default 0,
add column products_price8_qty int not null default 0,
add column products_qty_blocks int not null default 1");
$database->query();
echo '<li>altered product groups table added pricebreak fields</li>';

echo '<h3>1.1.97 to 1.1.98 database updates complete</h3>';
echo '<hr>';

}//end 1197 - 1198

//1198 - 1199
$database->setQuery("show columns from #__osc_orders_status");
$result = $database->loadObjectList();
$tcheck = array();
foreach($result as $check) {
$tcheck[]=$check->Field;
}

if (!in_array("public_flag" , $tcheck)){

echo '<h3>Doing the 1.1.98 - 1.1.99 Database upgrades</h3>';
echo '<h4>Database Optimisations for speed</h4>';

$database->setQuery("alter table #__osc_banners add index idx_banners_group (banners_group)"); 
$database->query();
echo '<li>Added index to banners table</li>';

$database->setQuery("alter table #__osc_banners_history add index idx_banners_history_banners_id (banners_id)"); 
$database->query();
echo '<li>added index to banners history table</li>';

$database->setQuery("alter table #__osc_currencies add index idx_currencies_code (code)"); 
$database->query();
echo '<li>added index to currencies table</li>';

$database->setQuery("alter table #__osc_customers add index idx_customers_email_address (customers_email_address)"); 
$database->query();
echo '<li>Added index to customers table</li>';

$database->setQuery("alter table #__osc_customers_basket add index idx_customers_basket_customers_id (customers_id)"); 
$database->query();
echo '<li>added Index to basket table</li>';

$database->setQuery("alter table #__osc_customers_basket_attributes add index idx_customers_basket_att_customers_id (customers_id)"); 
$database->query();
echo '<li>Added index to basket attributes</li>';

$database->setQuery("alter table #__osc_orders add index idx_orders_customers_id (customers_id)"); 
$database->query();
echo '<li>added index to orders table</li>';

$database->setQuery("alter table #__osc_orders_products add index idx_orders_products_orders_id (orders_id)"); 
$database->query();
echo '<li>Added index to products ordered table</li>';

$database->setQuery("alter table #__osc_orders_products add index idx_orders_products_products_id (products_id)"); 
$database->query();
echo '<li>Added index to products ordered table</li>';

$database->setQuery("alter table #__osc_orders_status_history add index idx_orders_status_history_orders_id (orders_id)"); 
$database->query();
echo '<li>Added index to order status history table</li>';

$database->setQuery("alter table #__osc_orders_products_attributes add index idx_orders_products_att_orders_id (orders_id)"); 
$database->query();
echo '<li>Added index to order products attributes table</li>';

$database->setQuery("alter table #__osc_orders_products_download add index idx_orders_products_download_orders_id (orders_id)"); 
$database->query();
echo '<li>Added index to orders products download table</li>';

$database->setQuery("alter table #__osc_products add index idx_products_model (products_model)"); 
$database->query();
echo '<li>Added index to products model</li>';

$database->setQuery("alter table #__osc_products_attributes add index idx_products_attributes_products_id (products_id)"); 
$database->query();
echo '<li>Added index to products attributes table</li>';

$database->setQuery("alter table #__osc_reviews add index idx_reviews_products_id (products_id)"); 
$database->query();
echo '<li>Added index to reviews table</li>';

$database->setQuery("alter table #__osc_reviews add index idx_reviews_customers_id (customers_id)"); 
$database->query();
echo '<li>Added index to reviews table</li>';

$database->setQuery("alter table #__osc_specials add index idx_specials_products_id (products_id)"); 
$database->query();
echo '<li>Added index to specials table</li>';

$database->setQuery("alter table #__osc_zones add index idx_zones_to_geo_zones_country_id (zone_country_id)"); 
$database->query();
echo '<li>Added index to zones table</li>';


echo '<h4>Database additions </h4>';
$database->setQuery(" 
alter table #__osc_orders_status add public_flag int DEFAULT '1'"); 
$database->query();
echo '<li>Altered order status table added public_flag field, int, default 1</li>';

$database->setQuery("alter table #__osc_orders_status add downloads_flag int DEFAULT '0'"); 
$database->query();
echo '<li>Altered order status table added downloads_flag, int, default 0</li>';

$database->setQuery("alter table #__osc_orders modify payment_method varchar(255) NOT NULL"); 
$database->query();
echo '<li>Altered orders table enlarged payment method field</li>';

$database->setQuery("alter table #__osc_whos_online modify last_page_url text NOT NULL"); 
$database->query();
echo '<li>Altered table whos online enlarged last page url field</li>';

$database->setQuery("ALTER TABLE `#__osc_products` ADD `products_vidupload` VARCHAR(255) AFTER `products_image`");
$database->query();
echo '<li>Altered table products added video upload field</li>';

$database->setQuery("ALTER TABLE `#__osc_products` ADD `products_mp3` varchar(255) default NULL AFTER `products_vidupload`");
$database->query();
echo '<li>Altered table products added mp3 upload field</li>';

$database->setQuery("ALTER TABLE `#__osc_products` ADD `products_pdfupload` VARCHAR(64) AFTER `products_mp3`");
$database->query();
echo '<li>Added pdf upload field to products table</li>';

$database->setQuery("ALTER TABLE `#__osc_products` ADD `products_fileupload` VARCHAR(64) AFTER `products_image`");
$database->query();
echo '<li>Added file upload field to products table</li>';

$database->setQuery("CREATE TABLE if not exists `#__osc_auctions` (
  `auctions_id` int(11) NOT NULL auto_increment,
  `products_id` int(11) NOT NULL default '0',
  `auctions_starting_price` decimal(15,4) NOT NULL default '0.0000',
  `auctions_date_added` datetime default NULL,
  `auctions_last_modified` datetime default NULL,
  `expires_date` datetime NOT NULL default '2006-11-01 00:00:00',
  `date_status_change` datetime default NULL,
  `status` int(1) NOT NULL default '1',
  `overbid_amount` float(10,2) NOT NULL default '0.00',
  `notified` int(1) NOT NULL default '1',
  PRIMARY KEY  (`auctions_id`)
)");
$database->query();
echo '<li>Added Auctions table</li>';

$database->setQuery("CREATE TABLE if not exists `#__osc_auctions_bids` (
  `auctions_bids_id` int(11) NOT NULL auto_increment,
  `auctions_id` int(11) NOT NULL default '0',
  `customers_id` int(11) NOT NULL default '0',
  `bid_price` float(10,2) NOT NULL default '0.00',
  `bid_status` varchar(10) default NULL,
  `bid_date_added` datetime NOT NULL,
  PRIMARY KEY  (`auctions_bids_id`)
)");
$database->query();
echo '<li>Added Auction Bids Table</li>';

$database->setQuery("ALTER TABLE #__osc_customers_basket ADD auction_product int(1) NOT NULL default '1'");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('End of Auction  - Options', 'AUCTION_END_OPTIONS', '1', 'How do you want your auctions to end, select an option: <br />0 - Auction goes inactive<br />1 - Auction remains active but can''t be bid on', 1984, 1, '2006-11-13 19:26:24', '2006-11-11 13:23:56', NULL, 'tep_cfg_select_option(array(''0'', ''1''), ')");
$database->query();
$database->setQuery("INSERT INTO `#__osc_configuration_group` (`configuration_group_id`, `configuration_group_title`, `configuration_group_description`, `sort_order`, `visible`) VALUES (1984, 'Auction Listing', 'All configuration settings for the auctions module should go here', 1984, 1)");
$database->query();
echo '<li>configuration group details added for auctions</li>';

$database->setQuery("INSERT INTO `#__osc_configuration_group` (`configuration_group_id`, `configuration_group_title`, `configuration_group_description`, `sort_order`, `visible`) VALUES (1985, 'Excel Import', 'All configuration settings for the Excel import export should go here', 1985, 1)");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Price Tax setting', 'EP_PRICE_WITH_TAX', '1', '0 if you want the price without the tax included <br />1 if you want the price to be defined for import & export including tax.', 1985, 1, '2008-03-28 19:26:24', '2008-03-28 13:23:56', NULL, 'tep_cfg_select_option(array(''0'', ''1''), ')");
$database->query();
$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Price Tax setting', 'EP_REPLACE_QUOTES', '1', 'If you have extensive html in your descriptions and it's getting mangled on upload, turn this off<br />0 off <br />1 on.', 1985, 1, '2008-03-28 19:26:24', '2008-03-28 13:23:56', NULL, 'tep_cfg_select_option(array(''0'', ''1''), ')");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Send SMS', 'SMS_SEND', 'false', 'Do you want to recieve order notification SMS using <a href=\"http://affiliates.clickatell.com/central/campaigns/redir.php?cid=28347\" target=\"_blank\">Clickatell</a>', 12, 6, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, 'tep_cfg_select_option(array(''true'', ''false''),')");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS Originator', 'SMS_ORIGINATOR', '123456789', 'set this to the value you wish your SMS to appear from, stricly max of 16 numbers or 11 alphanumeric characters', 12, 7, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS API ID', 'SMS_API_ID', '123456789', 'This is the Api Id that you created in the clickatell web interface', 12, 8, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");

$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS API Userid', 'SMS_API_USERNAME', '123456789', 'This is your Clickatell username', 12, 9, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");

$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS API Password', 'SMS_API_PASSWORD', '123456789', 'This is your Clickatell password', 12, 10, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");

$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS Destination', 'SMS_API_DESTINATION', '123456789', 'Which number to send sms to', 12, 11, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");

$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('SMS Message', 'SMS_API_MESSAGE', 'New Order Placed', 'Subject of sms, will add customer name and order ammount to sms', 12, 12, '2008-03-13 19:26:24', '2008-03-13 19:26:24', NULL, '')");

$database->query();
$database->setQuery("update `configuration_group` set `configuration_group_title` = 'Email/SMS notifications', `configuration_group_description` = 'General setting for E-Mail transport and HTML E-Mails & SMS settings' where `configuration_group_title` = 'E-Mail Options'");
$database->query();

$query = "Update #__osc_configuration set configuration_value = '1.1.99' where configuration_key = 'ECJC_CURR_VERSION'";
$database->setQuery($query);
$database->query();
echo '<li>Versioning Updated<li>';
$database->setQuery("Update #__osc_configuration set configuration_group_id = '1' where configuration_key = 'SHOW_GA'");
$database->query();
echo '<li>Licence key display Updated</li>';


echo '<h3>Update to 1.1.99 Complete</h3>';
echo '<hr>';
}
//1199rc2

$database ->setQuery("Select count(*) as rc2 from #__osc_configuration where configuration_key = 'MAX_DISPLAY_FEATURED_PRODUCTS'");
$cnt = $database->loadResult();
if ($cnt < 1) {

echo '<h3>1.1.99 - 1.1.99RC2 Upgrades</h3>';
//ok not 1.1.99rc2 yet...
$database->setQuery("INSERT into #__osc_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added) values ('Maximum Display of Featured', 'MAX_DISPLAY_FEATURED_PRODUCTS', '6', 'This is the maximum amount of items to display on the front page, 0 to disable', '1', '18', '2008-03-13 19:26:24', '2008-03-13 19:26:24')");
$database->query();
echo '<li>Added config variable for featured products on main page</li>';

$database->setQuery("ALTER TABLE #__osc_whos_online ADD http_referer VARCHAR(255) NOT NULL");
$database->query();
$database->setQuery("ALTER TABLE #__osc_whos_online ADD user_agent VARCHAR(255) NOT NULL");
$database->query();
echo '<li>upgraded who`s online database for additional information</li>';

$database->setQuery("ALTER TABLE `#__osc_subscriptions` ADD PRIMARY KEY ( `productid` )");
$database->query();

$database->setQuery("Alter Table #__osc_orders Add `ip_address` VARCHAR(50) NOT NULL");
$database->query();


echo '<h3>Update to V1.1.99rc2 Complete';



//RC3:
//this can run 100 times for all we care...will never cause any issues:
$database->setQuery("ALTER TABLE `#__osc_affiliate_affiliate` CHANGE `affiliate_email_address` `affiliate_email_address` VARCHAR( 200 )  NOT NULL ,
CHANGE `affiliate_password` `affiliate_password` VARCHAR( 100 ) NOT NULL ");
$database->query();
$database->setQuery("Update #__osc_configuration set configuration_title='Licence Code', configuration_description='Your Licence code to remove limitations and google ads' where configuration_title='Show GA'");
$database->query();

}
echo '<h3>Update to V1.1.99rc3 Complete</h3>';

//1.2 --> no database changes thankfully

if(!defined('ENABLE_SSL')){
$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('End of Auction  - Options', 'AUCTION_END_PRODUCT', '1', 'How do you want your auctions to end, select an option: <br />0 - Product goes inactive<br />1 - Product remains active but can''t be bid on', 1984, 1, '2006-11-13 19:26:24', '2006-11-11 13:23:56', NULL, 'tep_cfg_select_option(array(''0'', ''1''), ')");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (`configuration_title`, `configuration_key`, `configuration_value`, `configuration_description`, `configuration_group_id`, `sort_order`, `last_modified`, `date_added`, `use_function`, `set_function`) VALUES ('Enable SSL Mode', 'ENABLE_SSL', 'false', 'Enable SSL Mode', 1, 1, '2006-11-13 19:26:24', '2006-11-11 13:23:56', NULL, 'tep_cfg_select_option(array(''true'', ''false''), ')");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES 
('Tax info and Shipping info', 'TAX_INFO_ONOFF', 'Disabled', 'Show info of Tax and shippping', 8, 18, '2004-06-29 07:10:52', '2004-06-29 07:10:52', NULL, 'tep_cfg_select_option(array(''Enabled'', ''Disabled''),')");
$database->query();

$database->setQuery("ALTER TABLE `#__osc_customers` 
ADD customers_credit_account_status varchar(9) NOT NULL default '0',
ADD customers_credit_status varchar(9) NOT NULL default '0', 
ADD customers_credit_amount decimal(9,2) NOT NULL default '0250.00', 
ADD customers_credit_left decimal(9,2) NOT NULL default '0250.00'");
$database->query();

$database->setQuery("ALTER TABLE `#__osc_orders` 
ADD `purchase_order_number` VARCHAR( 20 ),
ADD `customers_credit_amount` decimal(9,2) NOT NULL default '0.00',
ADD `customers_credit_left` decimal(9,2) NOT NULL default '0.00'");
$database->query();

$database->setQuery("ALTER TABLE `#__osc_orders` ADD INDEX ( `purchase_order_number` ) ");
$database->query();

}
echo  '<h3>Update to V1.2.0Rc1 Complete</h3>';

//1.2.1 updates
if(!defined('ADD_WATERMARK')){

$database->setQuery("UPDATE `#__osc_configuration` SET `set_function` = 'tep_cfg_select_option(array(''true'', ''false''),' WHERE `configuration_key` = 'TRACKER_EXCLUDE_BOTS' LIMIT 1");
$database->query();

$database->setQuery("INSERT INTO `#__osc_configuration` (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES 
('Watermark Images', 'ADD_WATERMARK', 'false', 'Add watermark to images', 4, 22, '2004-06-29 07:10:52', '2004-06-29 07:10:52', NULL, 'tep_cfg_select_option(array(''true'', ''false''),')");
$database->query();
$database->setQuery("INSERT INTO `#__osc_configuration` (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES 
('Backup image', 'BACKUP_IMAGE_BEFORE_WATERMARK', 'false', 'Backup images before watermarking?', 4, 22, '2004-06-29 07:10:52', '2004-06-29 07:10:52', NULL, 'tep_cfg_select_option(array(''true'', ''false''),')");
$database->query();
$database->setQuery("INSERT INTO `#__osc_configuration` (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES 
('Watermark Text', 'WATERMARK_TEXT', 'copyright image', 'Text to display as watermark?', 4, 22, '2004-06-29 07:10:52', '2004-06-29 07:10:52', NULL, '')");
$database->query();
$database->setQuery("UPDATE `#__osc_configuration` SET `configuration_description` = 'Enable tracking of visitors to the site?<br>Please visit http://www.joomla-host.co.za/components/com_mambowiki/index.php/ECJC_Configuration:_Tracking before switching on' where `configuration_key` = 'TRACKING_USE' LIMIT 1");
$database->query();

$database->setQuery("ALTER TABLE #__osc_orders ADD shipping_tax DECIMAL( 7, 4 ) DEFAULT '0.000' NOT NULL ");
$database->query();
$database->setQuery("INSERT into #__osc_configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('', 'Order Editor- Display Payment Method dropdown?', 'DISPLAY_PAYMENT_METHOD_DROPDOWN', 'true', 'Display Payment Method in Order Editor as dropdown menu (true) or as input field (false)', '1', '21', NULL, '2006-04-02 11:51:01', NULL, 'tep_cfg_select_option(array(\'true\', \'false\'),')");
$database->query();

}
echo '<h3>Update to V1.2.1RC1 Complete';

echo '<h2>Site Database now up to date</h2>';
echo '<a href="index3.php?option=com_oscommerce">Return to ECJC Admin</a>';

//1.2 --> no database changes thankfully


?>
